package cn.iocoder.yudao.module.of.controller.admin.taskapprovals;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.of.controller.admin.taskapprovals.vo.TaskApprovalPageReqVO;
import cn.iocoder.yudao.module.of.controller.admin.taskapprovals.vo.TaskApprovalPageResponseVO;
import cn.iocoder.yudao.module.of.controller.admin.taskapprovals.vo.TaskApprovalSaveReqVO;
import cn.iocoder.yudao.module.of.service.taskapproval.TaskApprovalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 任务审核下发")
@RestController
@RequestMapping("/of/task-approval")
@Validated
public class TaskApprovalController {

    @Resource
    private TaskApprovalService taskApprovalService;

    @PostMapping("/page")
    @Operation(summary = "获取分页")
    public CommonResult<PageResult<TaskApprovalPageResponseVO>> getPage(@Valid @RequestBody TaskApprovalPageReqVO req) {
        PageResult<TaskApprovalPageResponseVO> page = taskApprovalService.getPage(req);
        return success(page);
    }

    @PostMapping("/approval")
    @Operation(summary = "任务审批")
//    @PreAuthorize("@ss.hasPermission('of:task-approval:approval')")
    public CommonResult<Boolean> updateTaskApproval(@Valid @RequestBody TaskApprovalSaveReqVO updateReqVO) {
        taskApprovalService.taskApproval(updateReqVO);
        return success(true);
    }


}